﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Net;
using System.Text;
using GtsServer.Common;
using System.Web.Security;

namespace GtsServer.Service.IIS.WebTest
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //string iuput = "{\"info\":{\"phone\":{\"height\":960.0,\"mac\":\"18:87:96:B3:B1:43\",\"name\":\"super apple\",\"pid\":100,\"position\":\"c:\\fm2.apk\",\"version\":\"2.3.4\",\"width\":640.0},\"sim\":{\"area\":\"13800210500\",\"imei\":\"123456789012345\",\"imsi\":\"123456789012345\",\"number\":\"15201877668\",\"plmn\":\"46000\"},\"version\":{\"major\":2,\"minor\":3,\"reserved\":5}}}";
            //string input = "{\"info\":{\"phone\":{\"height\":960.0,\"mac\":\"18:87:96:B3:B1:43\",\"name\":\"super apple\",\"pid\":2,\"position\":\"c:\\fm2.apk\",\"version\":\"2.3.4\",\"width\":640.0},\"sim\":{\"area\":\"13800210500\",\"imei\":\"123456789012345\",\"imsi\":\"123456789012345\",\"number\":\"15201877668\",\"plmn\":\"46000\"},\"version\":{\"code\":1}}}";
            //string inputs = "{\"info\":{\"phone\":{\"height\":960.0,\"mac\":\"18:87:96:B3:B1:43\",\"name\":\"super apple\",\"pid\":100,\"position\":\"c:\\fm2.apk\",\"version\":\"2.3.4\",\"width\":640.0},\"sim\":{\"area\":\"13800210500\",\"imei\":\"123456789012345\",\"imsi\":\"123456789012345\",\"number\":\"15201877668\",\"plmn\":\"46000\"},\"version\":{\"code\":1}},\"task\":{\"earn_coin\":[100,100,100,100,100,100,100,100],\"bet_coin\":[100,100,100,100,100,100,100,100],\"win_times\":[100,100,100,100,100,100,100,100]},\"game\":{\"start\":100,\"cur_gains\":100,\"cur_run\":5,\"evt\":{\"xiaosanyuan\":{\"nub\":2,\"coin\":20},\"xiaosixi\":{\"nub\":2,\"coin\":20},\"dasanyuan\":{\"nub\":2,\"coin\":20},\"dasixi\":{\"nub\":2,\"coin\":20},\"kaihuoche\":{\"nub\":2,\"coin\":20},\"dahuoche\":{\"nub\":2,\"coin\":20},\"xiaomao\":{\"nub\":2,\"coin\":20}},\"thansize\":{\"earn_coin\":100,\"win_times\":100}}}";
            // HttpRequest req = new HttpRequest("", "http://117.135.163.65:9999/Service1.svc/NO100001s", "");
            //Label1.Text = DownloadWeb("http://117.135.163.66:9997/JiDongWang.aspx?stateid=DELIVRD&linkid=2013040200000059");
            //Label2.Text = DownloadWeb("http://Localhost:3001/TestService.svc/GetVersionAndNotice");
            Label3.Text = DownloadWeb("http://117.135.163.65:9999/TestService.svc/GetVersionAndNotice");
            //Label4.Text = DownloadWeb("http://117.135.163.65:9999/TestService.svc/GetPrizeRecord");
            //string input = "{\"GameID\" : 1002,\"Mould\" : \"All\",\"PID\" : 104,\"VersionCode\" : 3}";
            //Label4.Text = PostData(input, Encoding.UTF8, "http://117.135.163.65:3331/VersionService.svc/Version");




            //string input = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><MASP><HEAD><VERSION>1.0</VERSION><FROM_PLATFORM>MEGAJOY_SMS</FROM_PLATFORM<TO_PLATFORM>SMS</TO_PLATFORM></HEAD><DATA><DATA_TYPE>SMS</DATA_TYPE><GATEWAY>shcmcc</GATEWAY>"
            //                + "<LONGNUMBER>0216113</LONGNUMBER>"
            //                + "<MOBILE>13000000000</MOBILE>"
            //                + "<MSGCONTENT>测试消息</MSGCONTENT>"
            //                + "<MOTYPE>0</MOTYPE>"
            //                + "<LINKID>123</LINKID>"
            //                + "</DATA>"
            //                + "</MASP>";
            //Label3.Text = PostData("Age=20&Name=26", Encoding.UTF8, "http://117.135.163.66:9997/JiDongWang.aspx");


            //Label4.Text = PostData("", Encoding.UTF8, "http://117.135.163.65:9999/TestService.svc/GetPrizeManageListPost");
            //string input = "{\"id\":14,\"info\":{\"phone\":{\"height\":480,\"mac\":\"18:87:96:B3:B1:43\",\"name\":\"super apple\",\"pid\":100,\"position\":\"c:\\fm2.apk\",\"version\":\"2.3.4\",\"width\":320},\"sim\":{\"area\":\"13800210500\",\"imei\":\"123456789012345\",\"imsi\":\"123456789012345\",\"number\":\"15201877668\",\"plmn\":\"46000\"},\"version\":{\"code\":290}}}";
            //string input = "{\"charge\":{\"type\":1,\"mode\":2,\"appid\":3,\"chargeid\":12,\"gametype\":4,\"matchid\":5,\"money\":100},\"log\":\"|zfb_2_'2013-01-17   07:02:25'\",\"info\":{\"phone\":{\"height\":480,\"mac\":\"18:87:96:B3:B1:43\",\"name\":\"super apple\",\"pid\":100,\"position\":\"c:\\fm2.apk\",\"version\":\"2.3.4\",\"width\":320},\"sim\":{\"area\":\"13800210500\",\"imei\":\"123456789012345\",\"imsi\":\"123456789012345\",\"number\":\"15201877668\",\"plmn\":\"46000\"},\"version\":{\"code\":290}}}";
            //string input = "{\"info\":{\"phone\":{\"height\":480,\"mac\":\"18:87:96:B3:B1:43\",\"name\":\"super apple\",\"pid\":1,\"position\":\"c:\\fm2.apk\",\"version\":\"2.3.4\",\"width\":320},\"sim\":{\"area\":\"13800210500\",\"imei\":\"123456789012345\",\"imsi\":\"123456789012345\",\"number\":\"15201877668\",\"plmn\":\"46000\"},\"version\":{\"code\":290}}}";
            //string input = "{\"index\":3,\"info\":{\"phone\":{\"height\":480,\"mac\":\"18:87:96:B3:B1:43\",\"name\":\"super apple\",\"pid\":100,\"position\":\"c:\\fm2.apk\",\"version\":\"2.3.4\",\"width\":320},\"sim\":{\"area\":\"13800210500\",\"imei\":\"123456789012345\",\"imsi\":\"123456789012345\",\"number\":\"15201877668\",\"plmn\":\"46000\"},\"version\":{\"code\":290}}}";
            //Label1.Text = PostData(input, Encoding.UTF8, "http://117.135.163.65:9999/TestService.svc/GetMatchList");
            //string input = "{\"id\":8,\"info\":{\"phone\":{\"height\":480,\"mac\":\"18:87:96:B3:B1:43\",\"name\":\"super apple\",\"pid\":100,\"position\":\"c:\\fm2.apk\",\"version\":\"2.3.4\",\"width\":320},\"sim\":{\"area\":\"13800210500\",\"imei\":\"123456789012345\",\"imsi\":\"123456789012345\",\"number\":\"15201877668\",\"plmn\":\"46000\"},\"version\":{\"code\":290}}}";
            //Label1.Text = PostData(input, Encoding.UTF8, "http://117.135.163.65:9999/TestService.svc/GetMatchRank");
            //string input = "{\"id\":88,\"info\":{\"phone\":{\"height\":480,\"mac\":\"18:87:96:B3:B1:43\",\"name\":\"super apple\",\"pid\":1,\"position\":\"c:\\fm2.apk\",\"version\":\"2.3.4\",\"width\":320},\"sim\":{\"area\":\"13800210500\",\"imei\":\"123456789012345\",\"imsi\":\"123456789012345\",\"number\":\"15201877668\",\"plmn\":\"46000\"},\"version\":{\"code\":290}}}";
            //Label1.Text = PostData(input, Encoding.UTF8, "http://117.135.163.65:9999/TestService.svc/UseStage");
            //string input = "sign=XwwyA6Li/zEGe0qQ92QgGfGq4dAjF0EiR5ANQE4vRvhuaoL297DgNFGTVHeVNl9+J5t3bHc5FDhTl8KMDFqLcu9coi2vbskg8P8ZCxEiZqHK6YHsfWJYqtM8hfaVabupt6D7Sjh0iAlwzdTTi+9ZPe/9jGWir30x5fm5lC9fjkE=&sign_type=RSA&notify_data=<notify><seller_email>greatelsoft.mail@gmail.com</seller_email><partner>2088601123663503</partner><payment_type>1</payment_type><buyer_email>290678259@qq.com</buyer_email><trade_no>2013012136715024</trade_no><buyer_id>2088502865395247</buyer_id><quantity>1</quantity><total_fee>0.01</total_fee><use_coupon>N</use_coupon><is_total_fee_adjust>Y</is_total_fee_adjust><price>0.01</price><out_trade_no>2013012100000086</out_trade_no><gmt_create>2013-01-21 21:05:22</gmt_create><seller_id>2088601123663503</seller_id><subject>奖品2</subject><trade_status>TRADE_FINISHED</trade_status><discount>0.00</discount></notify>";
            //Label3.Text = DownloadWeb("http://117.135.163.65:2211/ZfbCallBack.ashx?out_trade_no=2013012000000030&trade_status=TRADE_FINISHED");
            //Label1.Text = PostData(input, Encoding.UTF8, "http://117.135.163.65:2211/ZfbCallBack.aspx");
            //string input = "{\"charge\":{\"type\":1,\"mode\":2,\"appid\":3,\"chargeid\":12,\"gametype\":4,\"matchid\":5,\"money\":100},\"log\":\"|zfb_2_'2013-01-17   07:02:25'\",\"info\":{\"phone\":{\"height\":480,\"mac\":\"18:87:96:B3:B1:43\",\"name\":\"super apple\",\"pid\":100,\"position\":\"c:\\fm2.apk\",\"version\":\"2.3.4\",\"width\":320},\"sim\":{\"area\":\"13800210500\",\"imei\":\"123456789012345\",\"imsi\":\"123456789012345\",\"number\":\"15201877668\",\"plmn\":\"46000\"},\"version\":{\"code\":290}}}";
            //Label1.Text = PostData(input, Encoding.UTF8, "http://117.135.163.65:9999/TestService.svc/ChargeZfb");
            //Label2.Text = PostData(inputs, Encoding.UTF8, "http://117.135.163.65:9999/TestService.svc/GetVersionAndNotice");
            //Label1.Text = PostData(input, Encoding.UTF8, "http://192.168.254.55:1234/TestService.svc/GetChance");
            //Label1.Text = DownloadWeb("http://192.168.254.41:1234/TestService.svc/GetPrizeList");
            //Label1.Text = PostData("iuput", Encoding.UTF8, "http://117.135.163.65:9999/TestService.svc/GetChance");
            //Label1.Text = PostData("", Encoding.UTF8, "http://117.135.163.65:9999/TestService.svc/GetChance");
            //Label1.Text = DownloadWeb("http://localhost:1234/Service.svc/AddTest?Age=20&Name=26");
            //Label2.Text = DownloadWeb("http://localhost:1234/Service.svc/ShowTest?Age=20&Name=26");
            //Label4.Text = DownloadWeb("http://localhost:1234/TestService.svc/GetPrizeDetailPost");
            //Label2.Text = PostData("", Encoding.UTF8, "http://117.135.163.65:9999/TestService.svc/GetPrizeManageListPost");
            //Label3.Text = PostData("", Encoding.UTF8, "http://117.135.163.65:9999/TestService.svc/GetPrizeDetailPost");
            //Label4.Text = PostData("", Encoding.UTF8, "http://117.135.163.65:9999/TestService.svc/GetPrizeRecordPost");


            //Label1.Text = DownloadWeb("http://192.168.254.55:1234/TestService.svc/AddTest?Age=20&Name=26");
            //Label2.Text = DownloadWeb("http://192.168.254.55:1234/TestService.svc/ShowTest?Age=20&Name=26");
            //Label3.Text = PostData("Age=30&Name=45", Encoding.UTF8, "http://117.135.163.65:9999/TestService.svc/AddPostTest");
            //Label4.Text = DownloadWeb("http://117.135.163.65:9999/TestService.svc/AddTest?Age=30&Name=55");
        }

        //public string Post(string urlP)
        //{
        //    System.Net.WebRequest ObjWebRequest = System.Net.WebRequest.Create(urlP);
        //    ObjWebRequest.Credentials = CredentialCache.DefaultCredentials;
        //    ((HttpWebRequest)ObjWebRequest).UserAgent = "5DO8";
        //    ObjWebRequest.Method = "POST";
        //    ObjWebRequest.ContentLength = Stringdata.ToCharArray().Length;
        //    ObjWebRequest.ContentType = "application/x-www-form-urlencoded";//Post
        //    ObjWebRequest.ContentType = "text/xml";//SOAP

        //    byte[] byteArray = UTF8Encoding.GetBytes(dataP);
        //    System.IO.Stream dataStream = ObjWebRequest.GetRequestStream();
        //    dataStream.Write(byteArray, 0, byteArray.Length);
        //    dataStream.Close();

        //    WebResponse Objresponse = ObjWebRequest.GetResponse();
        //    dataStream = Objresponse.GetResponseStream();

        //    StreamReader r = new StreamReader(dataStream);
        //    Response.Write(HttpUtility.HtmlEncode(r.ReadToEnd()));
        //    Stream outStream = System.IO.File.Create("Temp.data");

        //    byte[] buffer = new byte[1024];
        //    int l;
        //    do
        //    {
        //        l = dataStream.Read(buffer, 0, buffer.Length);
        //        if (l > 0) outStream.Write(buffer, 0, l);
        //    } while (l > 0);

        //    outStream.Close();

        //}
        public string PostData(string PostData, Encoding encoding, string url)
        {
            string str = string.Empty;
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);//创建req 
            request.Accept = "text/html, application/xhtml+xml, */*"; //接受文件   
            request.UserAgent = " Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; EmbeddedWB 14.52 from: http://www.bsalsa.com/ EmbeddedWB 14.52; .NET CLR 2.0.50727)"; // 模拟使用IE在浏览 
            request.UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)";
            request.KeepAlive = true;
            //if ((PostData != null & PostData.Length > 0) || url.Contains("?"))
            //{
            request.Method = "POST";
            request.ContentType = "application/x-www-form-urlencoded";
            byte[] b = Encoding.UTF8.GetBytes(PostData);
            request.ContentLength = b.Length;
            request.AutomaticDecompression = DecompressionMethods.GZip;
            System.IO.Stream sw = null;
            try
            {
                sw = request.GetRequestStream();
                sw.Write(b, 0, b.Length);

            }
            catch (System.Exception ex)
            {
                //LastErrorString = ex.Message;
                //return null;
            }
            finally
            {
                if (sw != null) { sw.Close(); }
            }
            WebResponse Objresponse = request.GetResponse();
            Stream dataStream = Objresponse.GetResponseStream();
            StreamReader r = new StreamReader(dataStream);
            str = r.ReadToEnd();
            //}
            return str;
        }

        static string DownloadWeb(string url)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            string content = string.Empty;
            using (Stream resStream = response.GetResponseStream())
            {
                Encoding encoding = Encoding.UTF8;
                StreamReader streamReader = new StreamReader(resStream, encoding);
                content = streamReader.ReadToEnd();
            }
            return content;
        }
    }
}
